package com.echo.fm.platform.hql;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Order;

import com.echo.util.ErrorException;

public interface IPersistence {

	/**
	 * 打开session连接
	 * 
	 * @return
	 * @throws ErrorException
	 */
	Session openSession() throws ErrorException;

	/**
	 * 关闭session连接
	 * 
	 * @param session
	 * @throws ErrorException
	 */
	public void closeSession(Session session) throws ErrorException;

	/**
	 * 更新操作
	 * 
	 * @param object
	 * @throws ErrorException
	 */
	public void update(Object object) throws ErrorException;

	/**
	 * 删除操作
	 * 
	 * @param object
	 * @throws ErrorException
	 */
	public void delete(Object object) throws ErrorException;

	/**
	 * 保存操作
	 * 
	 * @param object
	 * @throws ErrorException
	 */
	public void save(Object object) throws ErrorException;

	/**
	 * 初始化查询条件
	 * 
	 * @param criterions
	 * @return
	 */
	public List<Criterion> initCriterion(List<Criterion> criterions);

	/**
	 * 通过主键ID进行查询对象
	 * 
	 * @param clazz
	 * @param criterion
	 * @return
	 * @throws ErrorException
	 */
	public Object searchById(Class<?> clazz, Criterion criterion) throws ErrorException;

	/**
	 * 把List<Criterion>查询的条件，放到criteria中
	 * 
	 * @param criteria
	 * @param criterions
	 */
	public void loadCriterions(Criteria criteria, List<Criterion> criterions);

	/**
	 * list查询的
	 * 
	 * @param clazz：类名
	 * @param criterions:条件
	 * @return
	 * @throws ErrorException
	 */
	public List<? extends Object> searchList(Class<?> clazz, List<Criterion> criterions) throws ErrorException;

	/**
	 * list查询，加上Order排序
	 * 
	 * @param clazz
	 * @param criterions
	 * @param order
	 * @return
	 * @throws ErrorException
	 */
	public List<? extends Object> searchList(Class<?> clazz, List<Criterion> criterions, Order order)
			throws ErrorException;

	/**
	 * list查询，加上Order 排序，但是指定查询的最大条数
	 * 
	 * @param clazz
	 * @param criterions
	 * @param order
	 * @param maxResults
	 * @return
	 * @throws ErrorException
	 */
	public List<? extends Object> searchList(Class<?> clazz, List<Criterion> criterions, Order order,
			Integer maxResults) throws ErrorException;

	/**
	 * 分页进行list查询，设置有最大条数和开始的查询记录数
	 * 
	 * @param clazz
	 * @param criterions
	 * @param order
	 * @param firstResult
	 * @param maxResults
	 * @return
	 * @throws ErrorException
	 */
	public List<? extends Object> searchList(Class<?> clazz, List<Criterion> criterions, Order order,
			Integer firstResult, Integer maxResults) throws ErrorException;

	/**
	 * 分页进行list查询，每页开始查询的第一个数
	 * 
	 * @param clazz
	 * @param criterions
	 * @param order
	 * @param firstResult
	 * @return
	 * @throws ErrorException
	 */
	public List<? extends Object> pageList(Class<?> clazz, List<Criterion> criterions, Order order, Integer firstResult)
			throws ErrorException;

	/**
	 * 通过多个order排序字段进行list查询
	 * 
	 * @param clazz
	 * @param criterions
	 * @param order
	 * @param firstResult
	 * @return
	 * @throws ErrorException
	 */
	public List<? extends Object> pageList(Class<?> clazz, List<Criterion> criterions, List<Order> orders,
			Integer firstResult) throws ErrorException;

	/**
	 * 通过多条件查询，查询出总条数
	 * 
	 * @param clazz
	 * @param criterions
	 * @param order
	 * @param firstResult
	 * @param maxResults
	 * @return
	 * @throws ErrorException
	 */
	public int pageCount(Class<?> clazz, List<Criterion> criterions) throws ErrorException;

	/**
	 * 通过多条件进行查询，多个对象
	 * 
	 * @param clazz
	 * @param criterions
	 * @return
	 * @throws ErrorException
	 */
	public Object searchByUniqueCriterion(Class<?> clazz, List<Criterion> criterions) throws ErrorException;

	/**
	 * 通过单条件进行查询单个对象
	 * 
	 * @param clazz
	 * @param criterion
	 * @return
	 * @throws ErrorException
	 */
	public Object searchByUniqueCriterion(Class<?> clazz, Criterion criterion) throws ErrorException;

	/**
	 * 通过单条件和单个order进行查询单个对象
	 * 
	 * @param clazz
	 * @param criterion
	 * @param order
	 * @return
	 * @throws ErrorException
	 */
	public List<? extends Object> searchByCriterion(Class<?> clazz, Criterion criterion, Order order)
			throws ErrorException;

	/**
	 * 通过序列查询
	 * 
	 * @param seqName
	 * @return
	 * @throws ErrorException
	 */
	public String searchCurrSeq(String seqName) throws ErrorException;

	/**
	 * 通过sql语句进行删除，按纯sql进行删除
	 * 
	 * @param sql
	 * @throws ErrorException
	 */
	public void deleteWithSQL(String sql) throws ErrorException;

}
